﻿using System;
using System.Data;

namespace DAL
{
    public static class DalReportReceipt
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetReportReceipt(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Report_Receipt_Get");
        }
        public static DataTable GetReportReceiptFillter(string dateBegin,string dateEnd)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@DateBegin", dateBegin);
            Cls.AddParameter("@EndBegin", dateEnd);
            return Cls.GetData("sp_Report_Receipt_FillterDate");
        }
        public static DataTable GetReportReceiptEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", id);
            return Cls.GetData("sp_Report_Receipt_Get_Edit");
        }
        public static DataTable GetReportReceiptDetailTemp(int usersId)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", usersId);
            return Cls.GetData("sp_Report_Receipt_Detail_Get_Temp");
        }
        public static DataTable GetReportReceiptDetailTempSum(int usersId)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", usersId);
            return Cls.GetData("sp_Report_Receipt_Detail_Get_Temp_Sum");
        }
        public static DataTable GetReportReceiptDetail(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", id);
            return Cls.GetData("sp_Report_Receipt_Detail_Get");
        }
        public static DataTable GetReportReceiptDetailSum(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", id);
            return Cls.GetData("sp_Report_Receipt_Detail_Get_Sum");
        }
        #endregion

        #region[Insert-Delete-Update]
        public static bool Insert(EtReportReceipt obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_Code",obj.ReportReceipt_Code);
            Cls.AddParameter("@Amount_Total", obj.Amount_Total);
            Cls.AddParameter("@DateCreate", obj.DateCreate);
            Cls.AddParameter("@Note", obj.Note);
            Cls.AddParameter("@Lock", obj.Lock);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Insert");
        }
        public static bool InsertDetail(EtReportReceiptDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", obj.ReportReceipt_ID);
            Cls.AddParameter("@Receipt_ID", obj.Receipt_ID);
            Cls.AddParameter("@Lock", obj.Lock);
            Cls.AddParameter("@flag", obj.flag);
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Detail_Insert");
        }
        public static bool Update(EtReportReceipt obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", obj.ReportReceipt_ID);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Update");
        }
        public static bool Delete(EtReportReceipt obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", obj.ReportReceipt_ID);
            obj.Msg = Cls.ExecuteNonQueryOutput("sp_Report_Receipt_Delete", "@Msg");
            return true;
        }
        public static bool DeleteTemp(EtReportReceiptDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportDetail_Id", obj.ReportDetail_Id);
            Cls.AddParameter("@Receipt_ID", obj.Receipt_ID);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Detail_Delete_Temp");
        }
        public static bool DeleteDetail(EtReportReceiptDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportDetail_Id", obj.ReportDetail_Id);
            Cls.AddParameter("@Receipt_ID", obj.Receipt_ID);
            Cls.AddParameter("@ReportReceipt_ID", obj.ReportReceipt_ID);
            Cls.AddParameter("@Uses_Id", obj.Users_Id);
            Cls.AddParameter("@Reason", obj.Reason);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Detail_Delete");
        }
        public static bool DeleteTempAdd(EtReportReceiptDetail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.Users_Id);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Detail_Delete_Temp_Add");
        }
        public static bool LockUnlock(EtReportReceipt obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ReportReceipt_ID", obj.ReportReceipt_ID);
            Cls.AddParameter("@Lock", obj.Lock);
            return Cls.ExecuteNonQuery("sp_Report_Receipt_Lock_Unlock");
        }
        #endregion
    }

    public class EtReportReceipt
    {
        public int ReportReceipt_ID { get; set; }
        public string ReportReceipt_Code { get; set; }
        public DateTime DateCreate { get; set; }
        public float Amount_Total { get; set; }
        public bool Lock { get; set; }
        public string Note { get; set; }
        public int Receipt_ID { get; set; }
        public int Msg { get; set; }
        public int Users_Id { get; set; }
        public string Reason { get; set; }
    }
    public class EtReportReceiptDetail
    {
        public int ReportDetail_Id { get; set; }
        public int ? ReportReceipt_ID { get; set; }
        public int Receipt_ID { get; set; }
        public bool Lock { get; set; }
        public string Note { get; set; }
        public int flag { get; set; }
        public int Users_Id { get; set; }
        public string Reason { get; set; }
    }
}